local shenzhuo = fk.CreateSkill {

  name = "joy__shenzhuo",

  tags = { Skill.Compulsory, },

}



shenzhuo:addEffect(fk.TurnStart, {
  name = "joy__shenzhuo",
  events = {fk.TurnStart,fk.CardUseFinished},
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return
      (event == fk.TurnStart and target == player and player:hasSkill(shenzhuo.name)) or
      (target == player and
      player:hasSkill(shenzhuo.name) and
      data.card.trueName == "slash" and
      not data.card:isVirtual())
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TurnStart and player:hasSkill(shenzhuo.name) then
      room:notifySkillInvoked(player, "joy__shenzhuo", "drawcard")
      local ids = room:getCardsFromPileByRule("slash|.|.", 1, "DrawPile")
      if #ids > 0 then
        room:obtainCard(player, ids[1], false, fk.ReasonPrey)
      end
    else
      local choice = room:askForChoice(player, { "joy__shenzhuo_drawOne", "joy__shenzhuo_drawThree" }, shenzhuo.name)
      if choice == "joy__shenzhuo_drawOne" then
        player:drawCards(1, shenzhuo.name)
        room:addPlayerMark(player, "joy__shenzhuo-turn")
      else
        player:drawCards(3, shenzhuo.name)
        room:setPlayerMark(player, "@joy__shenzhuo_debuff-turn", "joy__shenzhuo_debuff")
     end
    end
  end,
})
shenzhuo:addEffect(fk.CardUseFinished, {
  name = "joy__shenzhuo",
  events = {fk.TurnStart,fk.CardUseFinished},
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return
      (event == fk.TurnStart and target == player and player:hasSkill(shenzhuo.name)) or
      (target == player and
      player:hasSkill(shenzhuo.name) and
      data.card.trueName == "slash" and
      not data.card:isVirtual())
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TurnStart and player:hasSkill(shenzhuo.name) then
      room:notifySkillInvoked(player, "joy__shenzhuo", "drawcard")
      local ids = room:getCardsFromPileByRule("slash|.|.", 1, "DrawPile")
      if #ids > 0 then
        room:obtainCard(player, ids[1], false, fk.ReasonPrey)
      end
    else
      local choice = room:askForChoice(player, { "joy__shenzhuo_drawOne", "joy__shenzhuo_drawThree" }, shenzhuo.name)
      if choice == "joy__shenzhuo_drawOne" then
        player:drawCards(1, shenzhuo.name)
        room:addPlayerMark(player, "joy__shenzhuo-turn")
      else
        player:drawCards(3, shenzhuo.name)
        room:setPlayerMark(player, "@joy__shenzhuo_debuff-turn", "joy__shenzhuo_debuff")
     end
    end
  end,
})

shenzhuo:addEffect("targetmod", {
  name = "#joy__shenzhuo-buff",
  residue_func = function(self, player, skill, scope)
    if skill.trueName == "slash_skill" and scope == Player.HistoryPhase then
      return player:getMark("joy__shenzhuo-turn")
    end
  end,
})

shenzhuo:addEffect("prohibit", {
  name = "#joy__shenzhuo_prohibit",
  prohibit_use = function(self, player, card)
    return player:getMark("@joy__shenzhuo_debuff-turn") ~= 0 and card.trueName == "slash"
  end,
})

return shenzhuo